<?php
class Hd{
    public static function run(){
        if(!is_dir("APP")){
            //1.目录创建
            self::createDir();
            //2.文件的复制
            self::copyFile();
        }
        //载入核心文件
        self::loadCore();
        //执行应用
        \Hdphp\Libs\App::run();
    }
    /**
     * 创建目录的方法
     */
    private static function createDir(){
        $dirArr = array(
            //放控制器的目录
            "App/Home/Controller",
            //放模板文件的目录
            "App/Home/View/view",
            //用户配置项文件
            "App/Home/Config",
            //公共资源
            "Public",
        );
        foreach ($dirArr as $key => $value){
            //不存在就创建
            is_dir($value) || mkdir($value,0777,true);
        }
    }
    private static function copyFile(){
        //复制用户配置项文件
        copy("Hdphp/Common/Config.php","APP/Home/Config/Config.php");
        //复制控制器文件
        copy("Hdphp/Common/IndexController.php","APP/Home/Controller/IndexController.php");
        copy("Hdphp/Common/head.html","APP/Home/view/view/head.html");
        //复制成功失败模板
        copy("Hdphp/Common/success.html","Public/success.html");
        copy("Hdphp/Common/error.html","Public/error.html");
    }
    private static function loadCore(){
        require "Hdphp/Libs/functions.php";
        require "Hdphp/Libs/Controller.php";
        //载入应用类
        require "Hdphp/Libs/App.php";
    }
}
Hd::run();